import ollama

# 流式输出方式
def api_generate(text: str):
    print(f"提问：{text}")
    stream = ollama.generate(stream=True, model='deepseek-r1:1.5b', prompt=text)
    for chunk in stream:
        if not chunk['done']:
            print(chunk['response'], end='', flush=True)
        else:
            print("\n【耗时】", chunk['total_duration'])

# 非流式调用
response = ollama.generate(model='deepseek-r1:1.5b', prompt='天空为什么是蓝色的？')